package com.peng.leetcode.tree;

/**
 * ExpandBinaryTree
 * LCP 67. 装饰树
 * https://leetcode.cn/problems/KnLfVT/
 *
 * <p>
 * Created on 2022/11/19
 *
 * @author lupeng
 */
public class ExpandBinaryTree {

    public TreeNode expandBinaryTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        if (root.left != null) {
            TreeNode l = root.left;
            TreeNode newLeft = new TreeNode(-1);
            root.left = newLeft;
            newLeft.left = l;
            expandBinaryTree(l);
        }
        if (root.right != null) {
            TreeNode r = root.right;
            TreeNode newRight = new TreeNode(-1);
            root.right = newRight;
            newRight.right = r;
            expandBinaryTree(r);
        }
        return root;
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
